package com.cw.lang.redis.service.impl;

import java.io.Serializable;
import java.util.Collection;
import java.util.Set;

import org.springframework.data.redis.connection.RedisZSetCommands;
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.data.redis.core.ZSetOperations.TypedTuple;

import com.cw.lang.redis.service.RedisForZSetService;

import lombok.Getter;
import lombok.Setter;

/**
 * redisTemplate.opsForZSet()操作有序set
 *
 * @author chenw
 * @version $$Id: RedisForZSetServiceImpl.java, v 0.1 2018/11/19 3:31 PM chenw Exp $$
 */

@Getter
@Setter
public class RedisForZSetServiceImpl<K extends Serializable, V extends Serializable> extends AbstractRedisService<K, V>
    implements RedisForZSetService<K, V> {

    @Override
    public Boolean add(K key, V value, double score) {
        return getRedisTemplate(key).opsForZSet()
            .add(key, value, score);
    }

    @Override
    public Long add(K key, Set<TypedTuple<V>> typedTuples) {
        return getRedisTemplate(key).opsForZSet()
            .add(key, typedTuples);
    }

    @Override
    public Long remove(K key, Object... values) {
        return getRedisTemplate(key).opsForZSet()
            .remove(key, values);
    }

    @Override
    public Double incrementScore(K key, V value, double delta) {
        return getRedisTemplate(key).opsForZSet()
            .incrementScore(key, value, delta);
    }

    @Override
    public Long rank(K key, Object o) {
        return getRedisTemplate(key).opsForZSet()
            .rank(key, o);
    }

    @Override
    public Long reverseRank(K key, Object o) {
        return getRedisTemplate(key).opsForZSet()
            .reverseRank(key, o);
    }

    @Override
    public Set<V> range(K key, long start, long end) {
        return getRedisTemplate(key).opsForZSet()
            .range(key, start, end);
    }

    @Override
    public Set<TypedTuple<V>> rangeWithScores(K key, long start, long end) {
        return getRedisTemplate(key).opsForZSet()
            .rangeWithScores(key, start, end);
    }

    @Override
    public Set<V> rangeByScore(K key, double min, double max) {
        return getRedisTemplate(key).opsForZSet()
            .rangeByScore(key, min, max);
    }

    @Override
    public Set<TypedTuple<V>> rangeByScoreWithScores(K key, double min, double max) {
        return getRedisTemplate(key).opsForZSet()
            .rangeByScoreWithScores(key, min, max);
    }

    @Override
    public Set<V> rangeByScore(K key, double min, double max, long offset, long count) {
        return getRedisTemplate(key).opsForZSet()
            .rangeByScore(key, min, max, offset, count);
    }

    @Override
    public Set<TypedTuple<V>> rangeByScoreWithScores(K key, double min, double max, long offset, long count) {
        return getRedisTemplate(key).opsForZSet()
            .rangeByScoreWithScores(key, min, max, offset, count);
    }

    @Override
    public Set<V> reverseRange(K key, long start, long end) {
        return getRedisTemplate(key).opsForZSet()
            .reverseRange(key, start, end);
    }

    @Override
    public Set<TypedTuple<V>> reverseRangeWithScores(K key, long start, long end) {
        return getRedisTemplate(key).opsForZSet()
            .reverseRangeWithScores(key, start, end);
    }

    @Override
    public Set<V> reverseRangeByScore(K key, double min, double max) {
        return getRedisTemplate(key).opsForZSet()
            .reverseRangeByScore(key, min, max);
    }

    @Override
    public Set<TypedTuple<V>> reverseRangeByScoreWithScores(K key, double min, double max) {
        return getRedisTemplate(key).opsForZSet()
            .reverseRangeByScoreWithScores(key, min, max);
    }

    @Override
    public Set<V> reverseRangeByScore(K key, double min, double max, long offset, long count) {
        return getRedisTemplate(key).opsForZSet()
            .reverseRangeByScore(key, min, max, offset, count);
    }

    @Override
    public Set<TypedTuple<V>> reverseRangeByScoreWithScores(K key, double min, double max, long offset, long count) {
        return getRedisTemplate(key).opsForZSet()
            .reverseRangeByScoreWithScores(key, min, max, offset, count);
    }

    @Override
    public Long count(K key, double min, double max) {
        return getRedisTemplate(key).opsForZSet()
            .count(key, min, max);
    }

    @Override
    public Long size(K key) {
        return getRedisTemplate(key).opsForZSet()
            .size(key);
    }

    @Override
    public Long zCard(K key) {
        return getRedisTemplate(key).opsForZSet()
            .zCard(key);
    }

    @Override
    public Double score(K key, Object o) {
        return getRedisTemplate(key).opsForZSet()
            .score(key, o);
    }

    @Override
    public Long removeRange(K key, long start, long end) {
        return getRedisTemplate(key).opsForZSet()
            .removeRange(key, start, end);
    }

    @Override
    public Long removeRangeByScore(K key, double min, double max) {
        return getRedisTemplate(key).opsForZSet()
            .removeRangeByScore(key, min, max);
    }

    @Override
    public Long unionAndStore(K key, K otherKey, K destKey) {
        return getRedisTemplate(key).opsForZSet()
            .unionAndStore(key, otherKey, destKey);
    }

    @Override
    public Long unionAndStore(K key, Collection<K> otherKeys, K destKey) {
        return getRedisTemplate(key).opsForZSet()
            .unionAndStore(key, otherKeys, destKey);
    }

    @Override
    public Long intersectAndStore(K key, K otherKey, K destKey) {
        return getRedisTemplate(key).opsForZSet()
            .intersectAndStore(key, otherKey, destKey);
    }

    @Override
    public Long intersectAndStore(K key, Collection<K> otherKeys, K destKey) {
        return getRedisTemplate(key).opsForZSet()
            .intersectAndStore(key, otherKeys, destKey);
    }

    @Override
    public Cursor<TypedTuple<V>> scan(K key, ScanOptions options) {
        return getRedisTemplate(key).opsForZSet()
            .scan(key, options);
    }

    @Override
    public Set<V> rangeByLex(K key, RedisZSetCommands.Range range) {
        return getRedisTemplate(key).opsForZSet()
            .rangeByLex(key, range);
    }

    @Override
    public Set<V> rangeByLex(K key, RedisZSetCommands.Range range, RedisZSetCommands.Limit limit) {
        return getRedisTemplate(key).opsForZSet()
            .rangeByLex(key, range, limit);
    }
}
